import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** IoT平台类型枚举 */
export enum IoTPlatformTypeEnum {
  /** IoTGateway */
  IoTGateway = 100,
  /** IoTSharp */
  IoTSharp = 200,
  /** ThingsBoard */
  ThingsBoard = 300,
  /** ThingsCloud */
  ThingsCloud = 400,
  /** 阿里云IoT */
  AliyunIoT = 500,
  /** 腾讯云IoT */
  TencentIoT = 600,
  /** 百度云IoT */
  BaiduIoT = 700,
  /** 华为云IoT */
  HuaweiIoT = 800,
  /** 中国移动IoT */
  OneNET = 900,
}

/** IoT平台类型实体 */
export class IoTPlatformTypeEntity {
  /** IoT平台类型 */
  PlatformType: IoTPlatformTypeEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(platformType: IoTPlatformTypeEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.PlatformType = platformType;
    this.Color = color;
    switch (platformType) {
      case IoTPlatformTypeEnum.IoTGateway:
        // this.Display = 'IoTGateway';
        this.Display = t('iot.enum.ioTPlatformType.ioTGateway');
        this.Color = this.Color ? this.Color : '#EF8538';
        break;
      case IoTPlatformTypeEnum.IoTSharp:
        // this.Display = 'IoTSharp';
        this.Display = t('iot.enum.ioTPlatformType.ioTSharp');
        this.Color = this.Color ? this.Color : '#454DF4';
        break;
      case IoTPlatformTypeEnum.ThingsBoard:
        // this.Display = 'ThingsBoard';
        this.Display = t('iot.enum.ioTPlatformType.thingsBoard');
        this.Color = this.Color ? this.Color : '#38567D';
        break;
      case IoTPlatformTypeEnum.ThingsCloud:
        // this.Display = 'ThingsCloud';
        this.Display = t('iot.enum.ioTPlatformType.thingsCloud');
        this.Color = this.Color ? this.Color : '#4B4CDC';
        break;
      case IoTPlatformTypeEnum.AliyunIoT:
        // this.Display = '阿里云IoT';
        this.Display = t('iot.enum.ioTPlatformType.aliyunIoT');
        this.Color = this.Color ? this.Color : '#EE722E';
        break;
      case IoTPlatformTypeEnum.TencentIoT:
        // this.Display = '腾讯云IoT';
        this.Display = t('iot.enum.ioTPlatformType.tencentIoT');
        this.Color = this.Color ? this.Color : '#297EF6';
        break;
      case IoTPlatformTypeEnum.BaiduIoT:
        // this.Display = '百度云IoT';
        this.Display = t('iot.enum.ioTPlatformType.baiduIoT');
        this.Color = this.Color ? this.Color : '#79C78D';
        break;
      case IoTPlatformTypeEnum.HuaweiIoT:
        // this.Display = '华为云IoT';
        this.Display = t('iot.enum.ioTPlatformType.huaweiIoT');
        this.Color = this.Color ? this.Color : '#D22C25';
        break;
      case IoTPlatformTypeEnum.OneNET:
        // this.Display = '中国移动IoT';
        this.Display = t('iot.enum.ioTPlatformType.oneNET');
        this.Color = this.Color ? this.Color : '#52BBF9';
        break;
    }
  }
}

//#region 获取IoT平台类型枚举架构
/**
 * 获取IoT平台类型枚举架构
 */
export function getIoTPlatformTypeEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: IoTPlatformTypeEntity[] = [
    new IoTPlatformTypeEntity(IoTPlatformTypeEnum.IoTGateway),
    new IoTPlatformTypeEntity(IoTPlatformTypeEnum.IoTSharp),
    new IoTPlatformTypeEntity(IoTPlatformTypeEnum.ThingsBoard),
    new IoTPlatformTypeEntity(IoTPlatformTypeEnum.ThingsCloud),
    new IoTPlatformTypeEntity(IoTPlatformTypeEnum.AliyunIoT),
    new IoTPlatformTypeEntity(IoTPlatformTypeEnum.TencentIoT),
    new IoTPlatformTypeEntity(IoTPlatformTypeEnum.BaiduIoT),
    new IoTPlatformTypeEntity(IoTPlatformTypeEnum.HuaweiIoT),
    new IoTPlatformTypeEntity(IoTPlatformTypeEnum.OneNET),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.PlatformType as number,
      label: item.Display,
      value: item.PlatformType as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
